/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package org.openbookformat.obffinder;

/**
 *
 * @author MUFEED
 */
public class Variable {
    public static final int INT_TYPE = 0;
    public static final int STRING_TYPE = 1;

    private int type;
    private String name;
    private String txt_before;
    private String txt_after;
    private String value;

    public Variable() {
        txt_before = "";
        txt_after = "";
    }
    public Variable(String name) {
        this();
        this.name = name;
    }

    public Variable(int type, String name) {
        this();
        this.type = type;
        this.name = name;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getType() {
        return type;
    }

    public void setType(int type) {
        this.type = type;
    }

    public void setType(String type) {
        setType(getType(type));
    }

    public String getTxt_after() {
        return txt_after;
    }

    public void setTxt_after(String txt_after) {
        this.txt_after = txt_after;
    }

    public String getTxt_before() {
        return txt_before;
    }

    public void setTxt_before(String txt_before) {
        this.txt_before = txt_before;
    }

    public String getValue() {
        return value;
    }

    public void setValue(String value) {
        this.value = value;
    }

    public static int getType(String type) {
        if (type.equals("int")) {
            return INT_TYPE;
        } else if(type.equals("String")) {
            return STRING_TYPE;
        }
        return -1;
    }

    public static String getTypeRegExpSubtitution(int type) {
        switch(type) {
            case INT_TYPE:
                return "[\\d]+";
            case STRING_TYPE:
                return ".*?";
            default:
                return ".*?";
        }
    }

    @Override
    public boolean equals(Object obj) {
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        final Variable other = (Variable) obj;
        if ((this.name == null) ? (other.name != null) : !this.name.equals(other.name)) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        String type_str = null;
        if (type == INT_TYPE)
            type_str = "int";
        if (type == STRING_TYPE)
            type_str = "String";

        return "[" + name + "," + type_str + "," + value + ","+ txt_before + "," + txt_after
                + "]";
    }
}
